package br.com.viewcar.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class FileUtils {

	private static final Log logger = LogFactory.getLog(FileUtils.class);

	public static String readFile(File fileName) {

		char[] buffer = null;

		try {

			BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));
			buffer = new char[(int)fileName.length()];
			int i = 0;
			int c = bufferedReader.read();
			while (c != -1) {
				buffer[i++] = (char)c;
				c = bufferedReader.read();
			}
		} catch (FileNotFoundException e) {
			logger.error(e.getMessage(), e);
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		}

		return new String(buffer);
	}

	public static List<SelectItem> getTypeFile(){

		List<SelectItem> result = new ArrayList<SelectItem>();
		result.add(new SelectItem(2, "XML"));
		result.add(new SelectItem(1, "TXT"));
		result.add(new SelectItem(3, "KML"));
		return result;
	}

}
